<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>{% block title %}乒乓球培训管理系统{% endblock %}</title>

    <!-- Bootstrap 5 CSS -->
    <link href="{{ url_for('static', filename='vendor/bootstrap/css/bootstrap.min.css') }}" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="{{ url_for('static', filename='vendor/bootstrap-icons/css/bootstrap-icons.css') }}" rel="stylesheet">
    <!-- 自定义样式 -->
    <link href="{{ url_for('static', filename='css/custom.css') }}" rel="stylesheet">

    {% block extra_css %}{% endblock %}
</head>
<body class="admin-layout">
    <!-- 侧边栏 -->
    <nav class="sidebar" id="sidebar">
        <div class="sidebar-header">
            <div class="sidebar-brand">
                <i class="bi bi-disc"></i>
                <span class="brand-text">乒乓球培训系统</span>
            </div>
            <button class="sidebar-toggle d-lg-none" id="sidebarToggle">
                <i class="bi bi-x-lg"></i>
            </button>
        </div>

        <div class="sidebar-menu">
            <ul class="nav flex-column">
                <!-- 仪表板 -->
                <li class="nav-item">
                    <a class="nav-link" href="{{ url_for('dashboard.index') }}" data-page="dashboard">
                        <i class="bi bi-speedometer2"></i>
                        <span class="nav-text">仪表板</span>
                    </a>
                </li>

                {% if current_user.is_authenticated %}
                    {% if current_user.is_super_admin() %}
                        <!-- 超级管理员菜单 -->
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('campus.list') }}" data-page="campus">
                                <i class="bi bi-building"></i>
                                <span class="nav-text">校区管理</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('students.list') }}" data-page="users">
                                <i class="bi bi-people"></i>
                                <span class="nav-text">用户管理</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('relations.index') }}" data-page="relations">
                                <i class="bi bi-arrow-left-right"></i>
                                <span class="nav-text">师生关系</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('admin_accounts.list_accounts') }}" data-page="finance">
                                <i class="bi bi-cash-stack"></i>
                                <span class="nav-text">财务管理</span>
                            </a>
                        </li>
                    {% elif current_user.is_campus_admin() %}
                        <!-- 校区管理员菜单 -->
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('students.list') }}" data-page="students">
                                <i class="bi bi-mortarboard"></i>
                                <span class="nav-text">学员管理</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('coaches.list') }}" data-page="coaches">
                                <i class="bi bi-person-check"></i>
                                <span class="nav-text">教练管理</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('tables.list') }}" data-page="tables">
                                <i class="bi bi-grid-3x3"></i>
                                <span class="nav-text">球台管理</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('admin_reservations.list_reservations') }}" data-page="reservations">
                                <i class="bi bi-calendar-check"></i>
                                <span class="nav-text">预约管理</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('admin_accounts.list_accounts') }}" data-page="accounts">
                                <i class="bi bi-wallet2"></i>
                                <span class="nav-text">账户管理</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('student_reservations.monthly_competitions') }}" data-page="monthly-competition">
                                <i class="bi bi-trophy"></i>
                                <span class="nav-text">月赛</span>
                            </a>
                        </li>
                    {% elif current_user.is_coach() %}
                        <!-- 教练菜单 -->
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('coach_student.my_students') }}" data-page="my-students">
                                <i class="bi bi-people"></i>
                                <span class="nav-text">我的学员</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('coach_student.applications') }}" data-page="applications">
                                <i class="bi bi-inbox"></i>
                                <span class="nav-text">学员申请</span>
                            </a>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="{{ url_for('coach_reservations.pending') }}" data-bs-toggle="collapse" data-bs-target="#reservationMenu" aria-expanded="false">
                                <i class="bi bi-calendar-check"></i>
                                <span class="nav-text">预约管理</span>
                            </a>
                            <div class="collapse" id="reservationMenu">
                                <ul class="nav flex-column ms-3">
                                    <li class="nav-item">
                                        <a class="nav-link" href="{{ url_for('coach_reservations.pending') }}" data-page="pending-reservations">
                                            <i class="bi bi-clock"></i>
                                            <span class="nav-text">待确认预约</span>
                                        </a>
                                    </li>
                                    <li class="nav-item">
                                        <a class="nav-link" href="{{ url_for('coach_reservations.confirmed') }}" data-page="confirmed-reservations">
                                            <i class="bi bi-check-circle"></i>
                                            <span class="nav-text">已确认预约</span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('coach_reservations.schedule') }}" data-page="my-schedule">
                                <i class="bi bi-calendar3"></i>
                                <span class="nav-text">我的课程表</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('evaluations.index') }}" data-page="evaluations">
                                <i class="bi bi-star"></i>
                                <span class="nav-text">课程评价</span>
                            </a>
                        </li>
                    {% elif current_user.is_student() %}
                        <!-- 学员菜单 -->
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('student_coach.search') }}" data-page="find-coach">
                                <i class="bi bi-search"></i>
                                <span class="nav-text">寻找教练</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('student_coach.my_coaches') }}" data-page="my-coaches">
                                <i class="bi bi-person-hearts"></i>
                                <span class="nav-text">我的教练</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('student_coach.applications') }}" data-page="applications">
                                <i class="bi bi-clipboard-check"></i>
                                <span class="nav-text">申请记录</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('student_reservations.index') }}" data-page="my-reservations">
                                <i class="bi bi-calendar-event"></i>
                                <span class="nav-text">我的预约</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('accounts.balance') }}" data-page="my-account">
                                <i class="bi bi-credit-card"></i>
                                <span class="nav-text">我的账户</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('evaluations.index') }}" data-page="my-evaluations">
                                <i class="bi bi-award"></i>
                                <span class="nav-text">学习评价</span>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{ url_for('student_reservations.monthly_competitions') }}" data-page="monthly-competition">
                                <i class="bi bi-trophy"></i>
                                <span class="nav-text">月赛</span>
                            </a>
                        </li>
                    {% endif %}

                    <!-- 公共菜单 -->
                {% endif %}
            </ul>
        </div>
    </nav>

    <!-- 主内容区域 -->
    <div class="main-wrapper">
        <!-- 顶部导航栏 -->
        <header class="main-header">
            <div class="header-left">
                <button class="sidebar-toggle" id="sidebarToggleDesktop">
                    <i class="bi bi-list"></i>
                </button>
                <h1 class="page-title">{% block page_title %}仪表板{% endblock %}</h1>
            </div>

            <div class="header-right">
                <!-- 用户信息 -->
                {% if current_user.is_authenticated %}
                <div class="user-info dropdown">
                    <button class="btn btn-link dropdown-toggle" type="button" id="userDropdown" data-bs-toggle="dropdown">
                        {% if current_user.photo_url %}
                            <img src="{{ current_user.photo_url }}" alt="用户头像" class="user-avatar">
                        {% else %}
                            <i class="bi bi-person-circle"></i>
                        {% endif %}
                        <span class="user-name">{{ current_user.real_name }}</span>
                        <span class="user-role badge bg-{% if current_user.is_super_admin() %}danger{% elif current_user.is_campus_admin() %}primary{% elif current_user.is_coach() %}success{% else %}info{% endif %}">
                            {% if current_user.is_super_admin() %}
                                超级管理员
                            {% elif current_user.is_campus_admin() %}
                                校区管理员
                            {% elif current_user.is_coach() %}
                                教练
                            {% else %}
                                学员
                            {% endif %}
                        </span>
                    </button>
                    <ul class="dropdown-menu dropdown-menu-end">
                        <li><a class="dropdown-item" href="{{ url_for('profile.view') }}"><i class="bi bi-person me-2"></i>个人资料</a></li>
                        <li><a class="dropdown-item" href="{{ url_for('profile.edit') }}"><i class="bi bi-pencil-square me-2"></i>编辑资料</a></li>
                        <li><a class="dropdown-item" href="{{ url_for('profile.change_password') }}"><i class="bi bi-key me-2"></i>修改密码</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="{{ url_for('auth.logout') }}"><i class="bi bi-box-arrow-right me-2"></i>退出登录</a></li>
                    </ul>
                </div>
                {% else %}
                <div class="user-info">
                    <a href="{{ url_for('auth.login') }}" class="btn btn-primary">
                        <i class="bi bi-box-arrow-in-right me-2"></i>
                        登录
                    </a>
                </div>
                {% endif %}
            </div>
        </header>

        <!-- 主内容 -->
        <main class="main-content">
            <!-- Flash 消息 -->
            {% include 'components/alerts.html' %}

            <!-- 页面内容 -->
            {% block content %}{% endblock %}
        </main>

        <!-- 页脚 -->
        <footer class="main-footer">
            <div class="footer-content">
                <span>&copy; 2025 乒乓球培训管理系统. 保留所有权利.</span>
                <span class="footer-version">版本 1.0.0</span>
            </div>
        </footer>
    </div>

    <!-- 移动端遮罩层 -->
    <div class="sidebar-overlay" id="sidebarOverlay"></div>

    <!-- Bootstrap 5 JS -->
    <script src="{{ url_for('static', filename='vendor/bootstrap/js/bootstrap.bundle.min.js') }}"></script>
    <!-- jQuery -->
    <script src="{{ url_for('static', filename='vendor/jquery/jquery.min.js') }}"></script>
    <!-- 自定义 JS -->
    <script src="{{ url_for('static', filename='js/admin.js') }}"></script>
    <script src="{{ url_for('static', filename='js/ui-components.js') }}"></script>

    {% block extra_js %}{% endblock %}
</body>
</html>
